package map;

import java.util.*;


public class TestMap {
    public static void test1(){
        Map<String, String> map = new TreeMap<>();
        map.put("黑旋风", "李逵");
        map.put("及时雨", "宋江");
        map.put("小李广", "花荣");
        map.put("鼓上骚", "时迁");
        map.put("小偷", "时迁");
        Set<String> keySet = map.keySet();
        for (String key : keySet){
            System.out.println(key);
        }
        map.put("花和尚", null);
        System.out.println(map.containsKey("及时雨"));
        System.out.println(map.containsKey("孙悟空"));
        System.out.println(map.containsValue("花荣"));
        System.out.println(map.containsValue("行者孙"));

        Collection<String> values = map.values();
        for (String v : values){
            System.out.println(v);
        }
        map.put("花和尚", "鲁智深");
        Set<Map.Entry<String, String>> entrySet = map.entrySet();
        for(Map.Entry<String, String> entry : entrySet){
            System.out.println(entry.getKey() + "->" + entry.getValue());
        }

        Map<Integer, String> m = new HashMap<>();
        for(int i = 1; i <= 10; i++){
            m.put(i, null);
        }

        m.clear();

        System.out.println(m.size());
    }

    public static void test2(){
        //Set<String> set = new HashSet<>();
        Set<String> set = new TreeSet<>();
        set.add("星期一");
        set.add("星期二");
        set.add("星期三");
        set.add("星期四");
        set.add("星期五");
        set.add("星期六");
        set.add("星期天");
        System.out.println(set.size());
        for (String s : set){
            System.out.print(s + " ");
            System.out.println(s.hashCode());
        }
        System.out.println();
        System.out.println(set);
        //System.out.println(set.add(null));
        System.out.println(set.remove(null));

        System.out.println(set.contains("星期四"));
        System.out.println(set.remove("星期二"));
        System.out.println(set.remove("星期二"));

        Iterator<String> it = set.iterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();

        System.out.println(set);
    }
    public static void main(String[] args) {
        //test1();    //Map的使用练习
        test2();    //Set的使用练习

    }
}
